<?php
namespace app\modules\api\controllers;

use yii;
use app\modules\api\service\StaffService;

class StaffController extends BaseController
{
    public $enableCsrfValidation = false;

    /**
     * 员工信息
     */
    public function actionList()
    {
        $service = new StaffService();
        $list = $service->staff();
        return json_encode($list);
    }

    /**
     * 添加员工
     */
    public function actionAdd()
    {
        if (yii::$app->request->isPost) {
            $data = $_POST;
            $table = yii::$app->db->tablePrefix.'staff';
            $re = yii::$app->db->createCommand()->insert($table,$data)->execute();
            if ($re) {
                echo json_encode(['code'=>1,'msg'=>'添加成功']);
            } else {
                echo json_encode(['code'=>0,'msg'=>'添加失败，请重试']);
            }
        }
    }
}